	//打开bind窗口
	function openBind(bindId, windowName, width, height, isDlg) {
		if (typeof window.onBindClick == "function") {
			if (!window.onBindClick()) return;
		}
		
		if (!windowName)
			windowName = "bind";
		
		if (!width)
			width = 800;
		
		if (!height)
			height = 600;
		
		if (isDlg) 
			openDialog(globeWebAppContext + "/brick/bindframe.jsp?globe.bind=" + bindId, width, height);
		else
			openWindow(globeWebAppContext + "/brick/bindframe.jsp?globe.bind=" + bindId, width, height, windowName);
		
	}
	
	/*--                      华丽的分隔线(BindFrame)                                --*/
	//在bind页面外面套的frm中使用的对象，用于记录临时的一些信息
	function BindFrame(bindId) {
		this.bindId = bindId;
		this.optionArray = new Array();
		this.modified = "false";
		
		
		//父页面
		this.targetWindow = (window.dialogArguments)?window.dialogArguments:window.opener;
		//父页面的相关变量
		eval("this.bindVar = this.targetWindow." + this.bindId + ";");
		//父页面的按钮
		this.bindObj = this.targetWindow.document.getElementById(bindId);
		
		//父页面的绑定控件信息以及选择页面的选项信息
		this.parentFieldName = this.bindObj.getAttribute("parentFieldName");
		this.selectFieldName = this.bindObj.getAttribute("selectFieldName");
		this.optionName = this.bindObj.getAttribute("optionName");
		
		//初始化需要选择页面的url
		this.url = this.bindObj.getAttribute("url");
		this.param = this.bindVar.getParam();
		this.url = (this.param && this.param != null)?this.url + this.param:this.url;
		
		//检查备选项是否被选中, value是备选项上的值, optionArray是已经选中的值
		//内部调用函数
		this.isInOptionArray = function (opt) {
			for(var j = 0; j < this.optionArray.length; j ++ ) {
				//拆分选中项和备选项的,
				var o = this.optionArray[j];
				var map = this.createMapByOption(opt);
				
				//比较
				if (isHashEqual(map, o)) return j;
			}
			return -1;
		};
		
		//向选中列表中添加一项
		//内部调用函数
		this.appendToOptionArray = function (opt) {
			if (this.isInOptionArray(opt) != -1) return;
			this.optionArray[this.optionArray.length] = this.createMapByOption(opt);
			if (this.modified)
				this.modified = "true";
		};
		//从已经选中的optionarrya移去一项
		//内部调用函数
		this.removeFromOptionArray = function (opt) {
			if ((m = this.isInOptionArray(opt)) == -1) return;
			while (m < this.optionArray.length) {
				this.optionArray[m] = this.optionArray[m+1];
				m++;
			}
			this.optionArray.length--;
	
			if (this.modified)
				this.modified = "true";
	
			return;
		};
		//根据opt创建相关的map
		this.createMapByOption = function createMapByOption(opt) {
			var fields = this.selectFieldName.split(",");
			var ret = {};
			for(var i = 0; i < fields.length; i ++ ) {
				ret[fields[i]] = (opt.getAttribute(fields[i]) == null)?"":opt.getAttribute(fields[i]);
			}
			return ret;
		};
	}
	
	//页面被重新装入时,或者树被load时,将选中的值填上
	BindFrame.prototype.initAllOptionOnLoad = function (doc) {
		var optionObj = doc.getElementsByName(this.optionName);
		//选中被选的项
		for (var i = 0; i < optionObj.length; i ++) {
			optionObj[i].checked = (this.isInOptionArray(optionObj[i]) != -1);
		}
	}
	
	//在页面被卸载前,将选中的参数,计入frm页面中的optionArray中
	BindFrame.prototype.checkAllOptionOnUnLoad = function (doc) {
		var optionObj = doc.getElementsByName(this.optionName);
		for (var i = 0; i < optionObj.length; i ++) {
			if (optionObj[i].checked) {
				if (optionObj[i].type == 'radio') this.optionArray.length = 0;
				this.appendToOptionArray(optionObj[i]);
			} else {
				this.removeFromOptionArray(optionObj[i]);
			}
		}
	}
	
	//获取所有被选中的项
	BindFrame.prototype.displayBind = function (doc) {
		var d = "";		
		this.checkAllOptionOnUnLoad(doc);
		
		for(var j = 0; j < this.optionArray.length; j ++ ) {
			d += hashToString(this.optionArray[j]) + ",\n";
		}
		
		return (d.length != 0)?d.substring(0, d.length - 2):d;
	}

	//将选中的项回填
	//doc:选择页面所在的document
	BindFrame.prototype.doBind = function (doc) {
		
		//将页面选中的值,填入frm页面中
		this.checkAllOptionOnUnLoad(doc);	
		if (typeof this.onStartBind == "function") {
			if (!this.onStartBind()) return;
		}
		
		//分隔回填的input项的名称,并新建一个存储对应的value的数组
		var fields = this.parentFieldName.split(",");
		var sfs = this.selectFieldName.split(",")
		var values = new Array(fields.length);
		for(var j = 0; j < fields.length; j++) {
			values[j] = "";
		}

		if (this.modified == "true") {
			//遍历optionArray,开始回填
			for(var i = 0; i < this.optionArray.length; i++) {
				var optionMap = this.optionArray[i];
				//回填value
				for(j = 0; j < fields.length; j++) {
					values[j] = values[j] + optionMap[sfs[j]] + ",";
				}
			}
	
			//去掉每个value最后多的一个","
			for(var j = 0; j < fields.length; j++) {
				if(values[j].length != 0) {
					values[j] = values[j].substring(0, values[j].length-1);
				}
			}
			
			//回填
			for(var j = 0; j < fields.length; j++) {
				if (!this.targetWindow.document.getElementById(fields[j])) continue;
				this.targetWindow.document.getElementById(fields[j]).value = values[j];
				//触发input改变的事件
				if (typeofFunction(this.targetWindow.document.getElementById(fields[j]), "onchange"))
					this.targetWindow.document.getElementById(fields[j]).onchange();
			}			
		}
						
		if (typeof this.onEndBind == "function") {
			this.onEndBind();
		}
				
		this.closeBind();
	}
	
	//在frm页面中获取父页面中已经填写的选项
	//并初始化道optionArray中
	BindFrame.prototype.revertBind = function () {	
		var fields = this.parentFieldName.split(",");
		var sfs = this.selectFieldName.split(",");
			
		var values = new Array(fields.length);
		var min = 65535;
		for(var j = 0; j < fields.length; j++) {
			//如果没有该控件，跳过
			if (!this.targetWindow.document.getElementById(fields[j])) continue;
			
			//将控件中的值按照逗号分割
			values[j] = this.targetWindow.document.getElementById(fields[j]).value.split(",");
			
			//如果多个控件出现不整齐的情况，取最小值
			if (this.targetWindow.document.getElementById(fields[j]).value != "")
				min = (values[j].length < min)?values[j].length:min;
		}		
		
		if (min == 65535) return;
		
		for(var i = 0; i < min; i++) {
			var optionMap = {};
			for(var j = 0; j < fields.length; j++) {
				//如果没有该控件，跳过
				if (!this.targetWindow.document.getElementById(fields[j])) continue;
				
				//将值放入每条记录的map中
				if (this.targetWindow.document.getElementById(fields[j]).value != "")
					optionMap[sfs[j]] = values[j][i];
				else
					optionMap[sfs[j]] = "";
			}
			this.optionArray[i] = optionMap;
		}
	}
	
	
	//清除所有选中的关联
	BindFrame.prototype.clearBind = function (doc) {
		this.optionArray.length = 0;
		var optionObj = doc.getElementsByName(this.optionName);
		for (var i = 0; i < optionObj.length; i ++)
			optionObj[i].checked = false;
		if (this.modified)
			this.modified = "true";
	}
	
	//关闭窗口
	BindFrame.prototype.closeBind = function () {
		if (window.parent)
			window.parent.close();
		else
			window.close();
	}
	

	
	
	
	
	/*--                      华丽的分隔线(bind)                                --*/
	//以下是bind对象相关的方法
	function Bind(bindId) {
		this.bindId = bindId;
		this.bindObj = document.getElementById(bindId);
		//记录dependon的参数
		this.param = {};
		this.free = {};
		
		this.setParam = function (paramName, paramValue) {	
			if (paramName && paramName != "" && paramValue && paramValue != "") {
				this.param[paramName] = paramValue;
			}	
		};
		
		this.getParam = function () {
			return hashToParam(this.param);
		}
		this.isFree = function () {
			return hashToBool(this.free);
		}
	}	
		
	Bind.prototype.dependOn = function (dependOnId, weakDepend, dependParam) {
		var obj = this;
		
		//不是弱依赖关系，将按钮disable
		if (!weakDepend) {
			obj.bindObj.disabled = true;
		}
		
		var dependObj = document.getElementById(dependOnId);
		if (dependObj) {
			var change = function () {
				//以下是和控件相关的方法
				//如果依赖的控件值不为空
				if (dependObj.value && dependObj.value != "") {
					//开锁
					obj.free[dependOnId] = true;
					//enable按钮
					if (obj.isFree())
						obj.bindObj.disabled = false;
					
					//参数带入
					if (dependParam)
						obj.setParam(dependParam, dependObj.value);
					else
						obj.setParam(dependObj.name, dependObj.value);
				//如果依赖的控件值空
				} else {
					//如果弱依赖关系，那么则保持开锁
					if (weakDepend) {
						obj.free[dependOnId] = true;
						if (obj.isFree())
							obj.bindObj.disabled = false;
							
					//不是弱依赖关系，那么disable按钮	
					} else {
						obj.free[dependOnId] = false;
						obj.bindObj.disabled = true;
					}
				}
			}
			
			//IE
			if (document.all)
				dependObj.attachEvent("onchange", change);
			//FireFox
			else
				dependObj.addEventListener("change", change, false);
			change();
		}
		
	}
